<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>
        根据数据库自动生成实体类等文件 - seventeenw的博客
      </title>
    <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  
  <meta name="theme-color" content="#000000" />
  
  <meta http-equiv="window-target" content="_top" />
  
  
  <meta name="description" content="根据修改一些参数，实现与数据库共通，自动生成 实体类、dto、Controller、Service、ServiceImpl、Dao、DaoIm" />
  <meta name="generator" content="Hugo 0.59.1 with theme pure" />
  <title>根据数据库自动生成实体类等文件 - seventeenw的博客</title>
  

  <link rel="stylesheet" href="https://seventeenw.gitee.io/blogs/css/style.css">
  <link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/9.15.10/styles/github.min.css">
  <meta property="og:title" content="根据数据库自动生成实体类等文件" />
<meta property="og:description" content="根据修改一些参数，实现与数据库共通，自动生成 实体类、dto、Controller、Service、ServiceImpl、Dao、DaoIm" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://seventeenw.gitee.io/blogs/2020/06/%E6%A0%B9%E6%8D%AE%E6%95%B0%E6%8D%AE%E5%BA%93%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E5%AE%9E%E4%BD%93%E7%B1%BB%E7%AD%89%E6%96%87%E4%BB%B6/" />
<meta property="article:published_time" content="2020-06-10T11:07:41+08:00" />
<meta property="article:modified_time" content="2020-06-10T11:07:41+08:00" />
<meta itemprop="name" content="根据数据库自动生成实体类等文件">
<meta itemprop="description" content="根据修改一些参数，实现与数据库共通，自动生成 实体类、dto、Controller、Service、ServiceImpl、Dao、DaoIm">


<meta itemprop="datePublished" content="2020-06-10T11:07:41&#43;08:00" />
<meta itemprop="dateModified" content="2020-06-10T11:07:41&#43;08:00" />
<meta itemprop="wordCount" content="4325">



<meta itemprop="keywords" content="" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="根据数据库自动生成实体类等文件"/>
<meta name="twitter:description" content="根据修改一些参数，实现与数据库共通，自动生成 实体类、dto、Controller、Service、ServiceImpl、Dao、DaoIm"/>

  <!--[if lte IE 9]>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
    <![endif]-->

  <!--[if lt IE 9]>
      <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->

</head>
  </head>
  <body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage"><header class="header" itemscope itemtype="http://schema.org/WPHeader">
    <div class="slimContent">
      <div class="navbar-header">
        <div class="profile-block text-center">
          <a id="avatar" href="https://github.com/wengshiquan" target="_blank">
            <img class="img-circle img-rotate" src="https://seventeenw.gitee.io/blogs/avatar.png" width="200" height="200">
          </a>
          <h2 id="name" class="hidden-xs hidden-sm">17Null</h2>
          <h3 id="title" class="hidden-xs hidden-sm hidden-md">Java Developer</h3>
          <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i>Fuzhou, China</small>
        </div><div class="search" id="search-form-wrap">
    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i
                        class="icon icon-search"></i></button>
            </span>
        </div>
        <div class="ins-search">
            <div class="ins-search-mask"></div>
            <div class="ins-search-container">
                <div class="ins-input-wrapper">
                    <input type="text" class="ins-search-input" placeholder="想要查找什么..."
                        x-webkit-speech />
                    <button type="button" class="close ins-close ins-selectable" data-dismiss="modal"
                        aria-label="Close"><span aria-hidden="true">×</span></button>
                </div>
                <div class="ins-section-wrapper">
                    <div class="ins-section-container"></div>
                </div>
            </div>
        </div>
    </form>
</div>
        <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
        <ul class="nav navbar-nav main-nav">
            <li class="menu-item menu-item-home">
                <a href="/blogs/">
                    <i class="icon icon-home-fill"></i>
                  <span class="menu-title">主页</span>
                </a>
            </li>
            <li class="menu-item menu-item-reprint">
                <a href="/blogs/reprint">
                    <i class="icon icon-star-fill"></i>
                  <span class="menu-title">转载</span>
                </a>
            </li>
            <li class="menu-item menu-item-about">
                <a href="/blogs/about">
                    <i class="icon icon-cup-fill"></i>
                  <span class="menu-title">关于</span>
                </a>
            </li>
        </ul>
      </nav>
    </div>
  </header>
  <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content"><p>一直想做前端的java程序员~</p>
            </div>
        </div>
    </div>
</div>

      <div class="widget">
    <h3 class="widget-title"> 分类</h3>
    <div class="widget-body">
        <ul class="category-list">
        </ul>
    </div>
</div>
      <div class="widget">
    <h3 class="widget-title"> 标签</h3>
    <div class="widget-body">
        <ul class="tag-list">
            
        </ul>

    </div>
</div>
      
<div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
        <ul class="recent-post-list list-unstyled no-thumbnail">
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://seventeenw.gitee.io/blogs/2020/06/vue-element-template-%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%9A%84%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B/" class="title">vue-element-template 从零开始的开发流程</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-25 22:51:58 &#43;0800 CST" itemprop="datePublished">2020-06-25</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://seventeenw.gitee.io/blogs/2020/06/vue-element-template-%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E7%9A%84%E5%BC%80%E5%8F%91%E6%97%A5%E5%BF%97/" class="title">vue-element-template 从零开始的开发日志</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-25 22:49:21 &#43;0800 CST" itemprop="datePublished">2020-06-25</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://seventeenw.gitee.io/blogs/2020/06/idea-springboot%E5%9B%BE%E6%A0%87%E4%B8%8D%E6%AD%A3%E7%A1%AE/" class="title">IDEA Springboot图标不正确</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-25 15:06:28 &#43;0800 CST" itemprop="datePublished">2020-06-25</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://seventeenw.gitee.io/blogs/2020/06/%E6%A0%B9%E6%8D%AE%E6%95%B0%E6%8D%AE%E5%BA%93%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E5%AE%9E%E4%BD%93%E7%B1%BB%E7%AD%89%E6%96%87%E4%BB%B6/" class="title">根据数据库自动生成实体类等文件</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-10 11:07:41 &#43;0800 CST" itemprop="datePublished">2020-06-10</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://seventeenw.gitee.io/blogs/2020/06/springboot-quartz%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E8%A7%A3%E5%86%B3%E6%97%A0%E6%B3%95%E6%B3%A8%E5%85%A5%E5%8F%8A%E6%8C%81%E4%B9%85%E5%8C%96%E7%9A%84%E9%97%AE%E9%A2%98/" class="title">springboot&#43;quartz定时任务（解决无法注入bean及持久化的问题）</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-05 00:09:03 &#43;0800 CST" itemprop="datePublished">2020-06-05</time>
                    </p>
                </div>
            </li>
        </ul>
    </div>
</div>
  </div>
</aside>

    
    
  <aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
    <div class="slimContent">
      <nav id="toc" class="article-toc">
        <h3 class="toc-title">文章目录</h3>
        <div class="toc-content always-active">
        </div>
      </nav>
    </div>
  </aside>
<main class="main" role="main"><div class="content">
  <article id="-" class="article article-type-" itemscope
    itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      <h1 itemprop="name">
  <a
    class="article-title"
    href="/blogs/2020/06/%E6%A0%B9%E6%8D%AE%E6%95%B0%E6%8D%AE%E5%BA%93%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E5%AE%9E%E4%BD%93%E7%B1%BB%E7%AD%89%E6%96%87%E4%BB%B6/"
    >根据数据库自动生成实体类等文件</a
  >
</h1>

      <div class="article-meta">
        <span class="article-date">
  <i class="icon icon-calendar-check"></i>
<a href="https://seventeenw.gitee.io/blogs/2020/06/%E6%A0%B9%E6%8D%AE%E6%95%B0%E6%8D%AE%E5%BA%93%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E5%AE%9E%E4%BD%93%E7%B1%BB%E7%AD%89%E6%96%87%E4%BB%B6/" class="article-date">
  <time datetime="2020-06-10 11:07:41 &#43;0800 CST" itemprop="datePublished">2020-06-10</time>
</a>
</span>

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blogs/2020/06/%E6%A0%B9%E6%8D%AE%E6%95%B0%E6%8D%AE%E5%BA%93%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E5%AE%9E%E4%BD%93%E7%B1%BB%E7%AD%89%E6%96%87%E4%BB%B6/#comments"
            class="article-comment-link">评论</a></span>
		<span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计:4325字</span>
		<span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长:9分 </span>
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      <p>根据修改一些参数，实现与数据库共通，自动生成 实体类、dto、Controller、Service、ServiceImpl、Dao、DaoImpl</p>

<p>运行类：</p>

<p>AutomaticMain.java</p>

<pre><code class="language-java">package com.mysql.test;

/**
 * @Title:Test
 * @Description:com.mysql.test.entity
 * @Auther:wengshiquan
 * @Version:1.0
 * @create2020/6/9 10:32
 */
public class AutomaticMain {

    // 数据库连接
    private static final String URL = &quot;jdbc:mysql://127.0.0.1:3306/irrigated?characterEncoding=utf8&amp;characterSetResults=utf8&amp;autoReconnect=true&amp;failOverReadOnly=false&amp;useSSL=false&amp;serverTimezone=UTC&quot;;
    private static String databaseName = &quot;irrigated&quot;; //获得数据库名
    private static final String NAME = &quot;root&quot;;
    private static final String PASS = &quot;root&quot;;
    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;
    private static String packageOutPath = &quot;/phoenix-irrigate/src/main/java/&quot;;
    private static String packageOutPathEntity = &quot;com.mysql.test.entity&quot;;// 指定实体生成所在包的路径
    private static String packageOutPathController = &quot;com.mysql.test.controller&quot;;// 指定controller生成所在包的路径
    private static String packageOutPathService = &quot;com.mysql.test.service&quot;;// 指定service生成所在包的路径
    private static String packageOutPathServiceImpl = &quot;com.mysql.test.service.impl&quot;;// 指定serviceImpl生成所在包的路径
    private static String packageOutPathDao = &quot;com.mysql.test.dao&quot;;// 指定dao生成所在包的路径
    private static String packageOutPathDaoImpl = &quot;com.mysql.test.dao.impl&quot;;// 指定daoImpl生成所在包的路径
    private static String packageOutPathDto = &quot;com.mysql.test.dto&quot;;// 指定daoImpl生成所在包的路径

    private static Boolean isSingleTable = true;//是否只生成单表  true:生成单表  false:该数据库所有表
    private static String singleTableName = &quot;irr_equipment&quot;;//想生成的单表表名

    /**
     * 当生成文件不在同一个工程时，建议使用这块内容
     */
    private static Boolean isGenEntity = true; //是否生成实体类
    private static Boolean isGenDto = true; //是否生成dto
    private static Boolean isGenController = true; //是否生成Controller
    private static Boolean isGenService = true; //是否生成Service
    private static Boolean isGenServiceImpl = true; //是否生成ServiceImpl
    private static Boolean isGenDao = true; //是否生成Dao
    private static Boolean isGenDaoImpl = true; //是否生成DaoImpl


    public static void main(String[] args) {
        new AutomaticExecuteUtils(DRIVER, URL, NAME, PASS,
                databaseName, packageOutPath, packageOutPathEntity,
                packageOutPathController, packageOutPathService, packageOutPathServiceImpl,
                packageOutPathDao, packageOutPathDaoImpl, packageOutPathDto,
                isSingleTable,singleTableName,
                isGenEntity,isGenDto,isGenController,isGenService,isGenServiceImpl,isGenDao,isGenDaoImpl);
        System.out.println(&quot;ok&quot;);
    }
}

</code></pre>

<p>实现方法类：</p>

<p>AutomaticExecuteUtils.java</p>

<pre><code class="language-java">package com.mysql.test;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;


/**
 * @Title:sql
 * @Description:com.mysql.test.entity
 * @Auther:wengshiquan
 * @Version:1.0
 * @create2020/6/9 10:25
 */
public class AutomaticExecuteUtils {

    // 数据库连接
    private String databaseName;
    private String packageOutPath;
    private String packageOutPathEntity;
    private String packageOutPathController;
    private String packageOutPathService;
    private String packageOutPathServiceImpl;
    private String packageOutPathDao;
    private String packageOutPathDaoImpl;
    private String packageOutPathDto;
    private Boolean isSingleTable;
    private String singleTableName;

    private Boolean isGenEntity;
    private Boolean isGenDto;
    private Boolean isGenController;
    private Boolean isGenService;
    private Boolean isGenServiceImpl;
    private Boolean isGenDao;
    private Boolean isGenDaoImpl;


    private Connection con = null;
    private Statement pStemt = null;
    private ResultSet rs = null;
    private ResultSetMetaData rsmd = null;

    private String[] tableNames;
    private String[] tablePre = {&quot;_&quot;};
    private String[] colsPre = {&quot;F_NB_&quot;, &quot;F_VC_&quot;, &quot;F_CR_&quot;, &quot;F_DT_&quot;};
    private String[] colnames; // 列名数组
    private String[] colTypes; // 列名类型数组
    private int[] colSizes; // 列名大小数组
    private int[] colDecimals;//列小数点
    private int[] isNullables;//是否可以为空

    public AutomaticExecuteUtils(String driver, String url, String name, String pass, String databaseName,
                                 String packageOutPath, String packageOutPathEntity, String packageOutPathController,
                                 String packageOutPathService, String packageOutPathServiceImpl, String packageOutPathDao,
                                 String packageOutPathDaoImpl, String packageOutPathDto, Boolean isSingleTable, String singleTableName,
                                 Boolean isGenEntity, Boolean isGenDto, Boolean isGenController, Boolean isGenService, Boolean isGenServiceImpl, Boolean isGenDao, Boolean isGenDaoImpl) {
        this.databaseName = databaseName;
        this.packageOutPath = packageOutPath;
        this.packageOutPathEntity = packageOutPathEntity;
        this.packageOutPathController = packageOutPathController;
        this.packageOutPathService = packageOutPathService;
        this.packageOutPathServiceImpl = packageOutPathServiceImpl;
        this.packageOutPathDao = packageOutPathDao;
        this.packageOutPathDaoImpl = packageOutPathDaoImpl;
        this.packageOutPathDto = packageOutPathDto;
        this.isSingleTable = isSingleTable;
        this.singleTableName = singleTableName;
        this.isGenEntity = isGenEntity;
        this.isGenDto = isGenDto;
        this.isGenController = isGenController;
        this.isGenService = isGenService;
        this.isGenServiceImpl = isGenServiceImpl;
        this.isGenDao = isGenDao;
        this.isGenDaoImpl = isGenDaoImpl;

        connect(driver, url, name, pass);
        getAllTables();
    }

    /**
     * 1、创建数据库连接
     */
    private void connect(String driver, String url, String name, String pass) {
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url, name, pass);
            pStemt = (Statement) con.createStatement();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

    private void colseConnect() {
        try {
            if (con != null) {
                con.close();
                con = null;
            }
            if (pStemt != null) {
                pStemt.close();
                pStemt = null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    /**
     * 获取所有表名
     */
    private void getAllTables() {
        String sql = &quot;select table_name from information_schema.tables where table_schema='&quot; + databaseName + &quot;' and table_type='base table'&quot;;
        try {
            rs = pStemt.executeQuery(sql);
            String s = &quot;&quot;;
            while (rs.next()) {
                s = s + rs.getString(&quot;TABLE_NAME&quot;) + &quot;,&quot;;
            }
            tableNames = s.substring(0, s.length() - 1).split(&quot;,&quot;);

            for (String tableName : tableNames) {
                if (isSingleTable) {
                    if (tableName.equalsIgnoreCase(singleTableName)) {
                        getTableInfo(tableName);
                    }
                } else {
                    getTableInfo(tableName);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            colseConnect();
        }
    }


    /**
     * 获取单个数据库表信息
     */
    private void getTableInfo(String tableName) {
        boolean f_sql = false; //是否需要导入包import java.sql.Timestamp;
        int size = 0;
        String sql = &quot;SELECT * FROM &quot; + tableName;
        try {
            rs = pStemt.executeQuery(sql);
            rsmd = rs.getMetaData();
            size = rsmd.getColumnCount();
            colnames = new String[size];
            colTypes = new String[size];
            colSizes = new int[size];
            colDecimals = new int[size];
            isNullables = new int[size];
            for (int i = 0; i &lt; size; i++) {
                colnames[i] = rsmd.getColumnName(i + 1); //数据库所有的表名
                colTypes[i] = rsmd.getColumnTypeName(i + 1); //数据库所有的数据类型
                colDecimals[i] = rsmd.getScale(i + 1);//小数
                isNullables[i] = rsmd.isNullable(i + 1);//是否可以为空
                if (colTypes[i].equalsIgnoreCase(&quot;date&quot;)
                        || colTypes[i].equalsIgnoreCase(&quot;timestamp&quot;)) {
                    f_sql = true;
                }
                colSizes[i] = rsmd.getColumnDisplaySize(i + 1);
            }

            String normTableName = normTableName(tableName);//获取数据库的列名
            //获取单张数据库表注释
            String tableComment = getTableComment(tableName);
            //获取单张数据库表的所有列信息
            StringBuffer tempSb = getColsInfo(tableName);

            //生成JBean文件
            if (isGenEntity) {
                genFile(tableName, getSb(tableName, tableComment, tempSb, f_sql));
            }
            //生成controller文件
            if (isGenDto) {
                genControllerFile(tableName, getControllerSb(tableName, getControllerMethods(tableName)));
            }
            //生成service文件
            if (isGenController) {
                genServiceFile(tableName, getServiceSb(tableName, getServiceMethods(tableName)));
            }
            //生成serviceImpl文件
            if (isGenService) {
                genServiceImplFile(tableName, getServiceImplSb(tableName, getServiceImplMethods(tableName)));
            }
            //生成dao文件
            if (isGenServiceImpl) {
                genDaoFile(tableName, getDaoSb(tableName, getDaoMethods(tableName)));
            }
            //生成daoImpl文件
            if (isGenDao) {
                genDaoImplFile(tableName, getDaoImplSb(tableName, getDaoImplMethods(tableName)));
            }
            //生成dto文件
            if (isGenDaoImpl) {
                genDtoFile(tableName, getDtoSb(tableName, getDtoMethods(tableName)));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成JavaBean文件
     *
     * @param content
     */
    private void genFile(String tableName, StringBuffer content) {
        try {
            File directory = new File(&quot;&quot;);
            String outputPath = directory.getAbsolutePath() + packageOutPath
                    + this.packageOutPathEntity.replace(&quot;.&quot;, &quot;/&quot;) + &quot;/&quot; + normTableName(tableName)
                    + &quot;.java&quot;;
            FileWriter fw = new FileWriter(outputPath);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(content);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 生成Controller文件
     */
    private void genControllerFile(String tableName, StringBuffer content) {
        try {
            File directory = new File(&quot;&quot;);
            String outputPath = directory.getAbsolutePath() + packageOutPath
                    + this.packageOutPathController.replace(&quot;.&quot;, &quot;/&quot;) + &quot;/&quot; + normTableName(tableName)
                    + &quot;Controller.java&quot;;
            FileWriter fw = new FileWriter(outputPath);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(content);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成Service文件
     */
    private void genServiceFile(String tableName, StringBuffer content) {
        try {
            File directory = new File(&quot;&quot;);
            String outputPath = directory.getAbsolutePath() + packageOutPath
                    + this.packageOutPathService.replace(&quot;.&quot;, &quot;/&quot;) + &quot;/&quot; + &quot;I&quot; + normTableName(tableName)
                    + &quot;Service.java&quot;;
            FileWriter fw = new FileWriter(outputPath);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(content);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成ServiceImpl文件
     */
    private void genServiceImplFile(String tableName, StringBuffer content) {
        try {
            File directory = new File(&quot;&quot;);
            String outputPath = directory.getAbsolutePath() + packageOutPath
                    + this.packageOutPathServiceImpl.replace(&quot;.&quot;, &quot;/&quot;) + &quot;/&quot; + normTableName(tableName)
                    + &quot;ServiceImpl.java&quot;;
            FileWriter fw = new FileWriter(outputPath);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(content);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 生成dao文件
     */
    private void genDaoFile(String tableName, StringBuffer content) {
        try {
            File directory = new File(&quot;&quot;);
            String outputPath = directory.getAbsolutePath() + packageOutPath
                    + this.packageOutPathDao.replace(&quot;.&quot;, &quot;/&quot;) + &quot;/&quot; + &quot;I&quot; + normTableName(tableName)
                    + &quot;Dao.java&quot;;
            FileWriter fw = new FileWriter(outputPath);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(content);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 生成daoImpl文件
     */
    private void genDaoImplFile(String tableName, StringBuffer content) {
        try {
            File directory = new File(&quot;&quot;);
            String outputPath = directory.getAbsolutePath() + packageOutPath
                    + this.packageOutPathDaoImpl.replace(&quot;.&quot;, &quot;/&quot;) + &quot;/&quot; + normTableName(tableName)
                    + &quot;DaoImpl.java&quot;;
            FileWriter fw = new FileWriter(outputPath);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(content);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成dto文件
     */
    private void genDtoFile(String tableName, StringBuffer content) {
        try {
            File directory = new File(&quot;&quot;);
            String outputPath = directory.getAbsolutePath() + packageOutPath
                    + this.packageOutPathDto.replace(&quot;.&quot;, &quot;/&quot;) + &quot;/&quot; + normTableName(tableName)
                    + &quot;Dto.java&quot;;
            FileWriter fw = new FileWriter(outputPath);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(content);
            pw.flush();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 获取单张数据库表的所有列信息
     * 1.获取所有的列名
     * 2.获取列类型
     * 3.获取列注释
     *
     * @param tableName 表名
     */
    private StringBuffer getColsInfo(String tableName) {
        StringBuffer temp = new StringBuffer();
        for (int i = 0; i &lt; colnames.length; i++) {
            temp.append(&quot;\t//&quot; + getColComment(tableName, colnames[i]) + &quot;\r\n &quot;);
            temp.append(&quot;\t@Column(name = \&quot;&quot; + getColsName(colnames[i]) + &quot;\&quot;&quot;);
            temp.append(&quot;,&quot;);

            if (isNullables[i] == 0) {
                temp.append(&quot;nullable = false &quot;);
                temp.append(&quot;,&quot;);
            }

            if (colTypes[i].equalsIgnoreCase(&quot;date&quot;)) {
                temp.append(&quot;columnDefinition = \&quot;datetime\&quot; )&quot;);
            } else if (colTypes[i].equalsIgnoreCase(&quot;decimal&quot;)) {
                int length = (colSizes[i]) - (colDecimals[i]);
                temp.append(&quot;columnDefinition = \&quot;decimal(&quot; + length + &quot;,&quot; + colDecimals[i] + &quot;)\&quot;) &quot;);
            } else {
                int length = colSizes[i];
                temp.append(&quot;length = &quot; + length + &quot;)&quot;);
            }
            temp.append(&quot; \r\n &quot;);
            temp.append(&quot;\tprivate &quot;);
            temp.append(getColsType(colTypes[i]) + &quot; &quot;);
            temp.append(normPropertyName(getColsName(colnames[i])) + &quot;;&quot;);
            temp.append(&quot;\r\n&quot;);
        }

        return temp;
    }

    /**
     * 构建StringBuffer缓存
     *
     * @param tableName
     * @param tableComment
     * @param colSb
     * @return
     */
    private StringBuffer getSb(String tableName, String tableComment, StringBuffer colSb, Boolean f_sql) {
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;package &quot; + this.packageOutPathEntity + &quot;;\r\n&quot;);
        // 判断是否导入工具包
        if (f_sql) {
            sb.append(&quot;\nimport java.sql.Timestamp;\r\n&quot;);
        }
        //导固定包
        sb.append(&quot;\nimport lombok.Getter;\r\n&quot;);
        sb.append(&quot;\nimport lombok.Setter;\r\n&quot;);
        sb.append(&quot;\nimport java.util.Date;\r\n&quot;);

        // 注释部分
        sb.append(&quot;   /**\r\n&quot;);
        java.util.Date date = new java.util.Date();
        sb.append(&quot;    * &quot; + date + &quot;\r\n&quot;);
        sb.append(&quot;    */ &quot;);
        // 实体部分

        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Entity&quot;);

        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Table(name = \&quot;&quot; + tableName.toUpperCase() + &quot;\&quot;, catalog = \&quot;&quot; + databaseName.toUpperCase() + &quot;\&quot;)&quot;);

        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Getter&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Setter&quot;);

        sb.append(&quot;\npublic class &quot; + normTableName(tableName) + &quot;{\r\n&quot;);
        sb.append(colSb);
        sb.append(&quot;\n}\r\n&quot;);
        return sb;
    }

    /**
     * Controller整体
     */
    private StringBuffer getControllerSb(String tableName, StringBuffer colSb) {
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;package &quot; + this.packageOutPathController + &quot;;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.apache.commons.logging.Log;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.apache.commons.logging.LogFactory;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.beans.factory.annotation.Autowired;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.web.bind.annotation.RequestMapping;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.web.bind.annotation.RequestMethod;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.web.bind.annotation.ResponseBody;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.stereotype.Controller;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.web.bind.annotation.RequestBody;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Controller&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@RequestMapping(\&quot;/&quot; + lowerFirstWord(normTableName(tableName)) + &quot;\&quot;)&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\npublic class &quot; + normTableName(tableName) + &quot;Controller&quot; + &quot;{\r\n&quot;);
        sb.append(colSb);
        sb.append(&quot;\n}\r\n&quot;);

        return sb;
    }

    /**
     * Controller内部方法
     */
    private StringBuffer getControllerMethods(String tableName) {
        String normTableName = normTableName(tableName);
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;\tprivate Log log = LogFactory.getLog(this.getClass());&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\tpublic Log getLog() { return log; }&quot;);
        sb.append(&quot;\r\n\n&quot;);
        sb.append(&quot;\t@Autowired&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\tprivate &quot; + &quot;I&quot; + normTableName + &quot;Service&quot; + &quot; i&quot; + normTableName + &quot;Service&quot; + &quot;;&quot;);
        sb.append(&quot;\r\n&quot;);


        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 分页查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param dto&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\t@RequestMapping(value = \&quot;/findListByPage\&quot;, method = RequestMethod.POST)&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t@ResponseBody&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\tpublic Object findListByPage(@RequestBody &quot; + normTableName + &quot;Dto &quot; + &quot;dto) {&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\treturn this.&quot; + &quot;i&quot; + normTableName + &quot;Service&quot; + &quot;.findListByPage(dto);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t}&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);

        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 新增&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param dto&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\t@RequestMapping(value = \&quot;/save\&quot;, method = RequestMethod.POST)&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t@ResponseBody&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\tpublic Object save(@RequestBody &quot; + normTableName + &quot;Dto &quot; + &quot;dto, SessionContext sessionContext) {&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\treturn this.&quot; + &quot;i&quot; + normTableName + &quot;Service&quot; + &quot;.save(dto);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t}&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);

        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 根据id查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param id&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\t@RequestMapping(value = \&quot;/findById\&quot;, method = RequestMethod.GET)&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t@ResponseBody&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\tpublic Object findById(String id) {&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\treturn this.&quot; + &quot;i&quot; + normTableName + &quot;Service&quot; + &quot;.findById(id);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t}&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);


        return sb;
    }

    /**
     * Service整体
     */
    private StringBuffer getServiceSb(String tableName, StringBuffer colSb) {
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;package &quot; + this.packageOutPathService + &quot;;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\npublic interface &quot; + &quot;I&quot; + normTableName(tableName) + &quot;Service&quot; + &quot;{\r\n&quot;);
        sb.append(colSb);
        sb.append(&quot;\n}\r\n&quot;);
        return sb;
    }


    /**
     * Service内部方法
     */
    private StringBuffer getServiceMethods(String tableName) {
        StringBuffer sb = new StringBuffer();
        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 分页查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param dto&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\tObject findListByPage(&quot; + normTableName(tableName) + &quot;Dto &quot; + &quot;dto);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);

        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 新增&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param dto&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\tObject save(&quot; + normTableName(tableName) + &quot;Dto &quot; + &quot;dto, SessionContext sessionContext);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);

        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 根据id查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param id&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\tObject findById(String id);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        return sb;
    }

    /**
     * ServiceImpl整体
     */
    private StringBuffer getServiceImplSb(String tableName, StringBuffer colSb) {
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;package &quot; + this.packageOutPathServiceImpl + &quot;;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.beans.factory.annotation.Autowired;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.stereotype.Service;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import com.nz.phoenix.common.utils.Identifier;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import com.nz.phoenix.core.db.builder.QueryBeanBuilder;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;import org.springframework.beans.BeanUtils;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Service&quot;);
        sb.append(&quot;\npublic class &quot; + normTableName(tableName) + &quot;ServiceImpl implements &quot; + &quot;I&quot; + normTableName(tableName) + &quot;Service&quot; + &quot;{\r\n&quot;);
        sb.append(colSb);
        sb.append(&quot;\n}\r\n&quot;);
        return sb;
    }


    /**
     * ServiceImpl内部方法
     */
    private StringBuffer getServiceImplMethods(String tableName) {
        String normTableName = normTableName(tableName);
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;\t@Autowired&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\tprivate &quot; + &quot;I&quot; + normTableName + &quot;Dao&quot; + &quot; i&quot; + normTableName + &quot;Dao&quot; + &quot;;&quot;);
        sb.append(&quot;\r\n&quot;);

        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 分页查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param dto&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 方法一：单表分页查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 方法二：自建sql分页查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\tpublic Object findListByPage(&quot; + normTableName + &quot;Dto &quot; + &quot;dto) {&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t//TODO&quot; + &quot;\r\n&quot;);

        sb.append(&quot;\t//方法一&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\tQueryBeanBuilder builder = new QueryBeanBuilder();&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\tbuilder.currentPage(irrEquipmentDto.getPage());&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\tbuilder.pageSize(irrEquipmentDto.getRows());&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\treturn this.&quot; + &quot;i&quot; + normTableName + &quot;Dao&quot; + &quot;.findPagedListByQueryBean(builder.get());&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);

        sb.append(&quot;\t//方法二&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t//Map&lt;String,Object&gt; params = new HashMap&lt;&gt;();&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t//StringBuffer sql = new StringBuffer(\&quot;\&quot;);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t//return this.executeSqlQuery(sql.toString(),params,dto.getPage(),dto.getRows());&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t}&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);

        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 新增&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param dto&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\tpublic Object save(&quot; + normTableName + &quot;Dto &quot; + &quot;dto, SessionContext sessionContext) {&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t//TODO&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\tif(null!=dto &amp;&amp; null!=dto.getId()){&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t\t&quot; + normTableName + &quot; &quot; + &quot;entity&quot; + &quot;=this.i&quot; + normTableName + &quot;Dao.findById(dto.getId()).get();&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t\tBeanUtils.copyProperties(dto,entity,new String[]{\&quot;id\&quot;,\&quot;state\&quot;});&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t\treturn this.&quot; + &quot;i&quot; + normTableName + &quot;Dao&quot; + &quot;.update(entity);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t}else{&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t\t&quot; + normTableName + &quot; &quot; + &quot;entity&quot; + &quot;=new &quot; + normTableName + &quot;();&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t\tBeanUtils.copyProperties(dto,entity);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t\tentity.setId(Identifier.stringUUID());&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t\treturn this.&quot; + &quot;i&quot; + normTableName + &quot;Dao&quot; + &quot;.save(entity);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\t}&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t}&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);


        // 注释部分
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\t/**&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* 根据id查询&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @param id&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t* @return&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t*/ &quot; + &quot;\r\n&quot;);
        //方法部分
        sb.append(&quot;\tpublic Object findById(String id) {&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t\treturn this.&quot; + &quot;i&quot; + normTableName + &quot;Dao&quot; + &quot;.findById(id);&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\t}&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);

        return sb;
    }


    /**
     * Dao整体
     */
    private StringBuffer getDaoSb(String tableName, StringBuffer colSb) {
        String normTableName = normTableName(tableName);
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;package &quot; + this.packageOutPathDao + &quot;;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\npublic interface &quot; + &quot;I&quot; + normTableName + &quot;Dao extends IBaseDao&lt;&quot; + normTableName + &quot;,String&gt; &quot; + &quot;{\r\n&quot;);
        sb.append(colSb);
        sb.append(&quot;\n}\r\n&quot;);
        return sb;
    }

    /**
     * Dao内部方法
     */
    private StringBuffer getDaoMethods(String tableName) {
        StringBuffer sb = new StringBuffer();
        return sb;
    }


    /**
     * DaoImpl整体
     */
    private StringBuffer getDaoImplSb(String tableName, StringBuffer colSb) {
        String normTableName = normTableName(tableName);
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;package &quot; + this.packageOutPathDaoImpl + &quot;;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\nimport org.springframework.stereotype.Repository;&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;\n@Repository&quot; + &quot;\r\n&quot;);
        sb.append(&quot;\npublic class &quot; + normTableName + &quot;DaoImpl extends BaseDaoImpl&lt;&quot; + normTableName + &quot;,String&gt; implements &quot; + &quot;I&quot; + normTableName + &quot;Dao&quot; + &quot;{\r\n&quot;);
        sb.append(colSb);
        sb.append(&quot;\n}\r\n&quot;);
        return sb;
    }

    /**
     * DaoImpl内部方法
     */
    private StringBuffer getDaoImplMethods(String tableName) {
        StringBuffer sb = new StringBuffer();
        return sb;
    }


    /**
     * Dto整体
     */
    private StringBuffer getDtoSb(String tableName, StringBuffer colSb) {
        String normTableName = normTableName(tableName);
        StringBuffer sb = new StringBuffer();
        sb.append(&quot;package &quot; + this.packageOutPathDto + &quot;;\r\n&quot;);

        //导固定包
        sb.append(&quot;\nimport lombok.Getter;\r\n&quot;);
        sb.append(&quot;\nimport lombok.Setter;\r\n&quot;);
        sb.append(&quot;\nimport java.util.Date;\r\n&quot;);
        // 注释部分
        sb.append(&quot;   /**\r\n&quot;);
        java.util.Date date = new java.util.Date();
        sb.append(&quot;    * &quot; + date + &quot;\r\n&quot;);
        sb.append(&quot;    */ &quot;);
        // 实体部分

        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Getter&quot;);
        sb.append(&quot;\r\n&quot;);
        sb.append(&quot;@Setter&quot;);

        sb.append(&quot;\npublic class &quot; + normTableName + &quot;Dto extends BaseDto {\r\n&quot;);
        sb.append(colSb);
        sb.append(&quot;\n}\r\n&quot;);
        return sb;
    }


    /**
     * Dto属性
     */
    private StringBuffer getDtoMethods(String tableName) {
        StringBuffer temp = new StringBuffer();
        for (int i = 0; i &lt; colnames.length; i++) {
            temp.append(&quot; \r\n &quot;);
            temp.append(&quot;\t//&quot; + getColComment(tableName, colnames[i]) + &quot;\r\n &quot;);
            temp.append(&quot;\tprivate &quot;);
            temp.append(getColsType(colTypes[i]) + &quot; &quot;);
            temp.append(normPropertyName(getColsName(colnames[i])) + &quot;;&quot;);
            temp.append(&quot;\r\n&quot;);
        }
        return temp;
    }


    /**
     * 获取单张数据库表注释
     *
     * @param tableName
     * @return
     */
    private String getTableComment(String tableName) {

        String str = &quot;&quot;;
        String sql = &quot;select column_comment from INFORMATION_SCHEMA.Columns where&quot;
                + &quot; table_name='&quot; + tableName + &quot;' and table_schema='&quot; + databaseName + &quot;'&quot;;
        try {
            rs = pStemt.executeQuery(sql);
            while (rs.next()) {
                str = rs.getString(&quot;column_comment&quot;);
                if (null != str &amp;&amp; str.indexOf(&quot;\r\n&quot;) != -1) {
                    str = str.replace(&quot;\r\n&quot;, &quot;&quot;);
                }
                if (null != str &amp;&amp; str.indexOf(&quot;\n&quot;) != -1) {
                    str = str.replace(&quot;\n&quot;, &quot;&quot;);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return str;
    }

    /**
     * 获取列名
     *
     * @param str
     * @return
     */
    private String getColsName(String str) {
        for (String temp : colsPre) {
            int preIndex = str.indexOf(temp);
            if (preIndex &gt;= 0) {
                str = str.substring(preIndex + temp.length());
                str = str.replace(&quot;_&quot;, &quot;&quot;).toLowerCase();
            }
        }
        return str;
    }

    /**
     * 获取列类型
     *
     * @param sqlType
     * @return
     */
    private String getColsType(String sqlType) {
        if (sqlType.equalsIgnoreCase(&quot;double&quot;)) {
            return &quot;double&quot;;
        } else if (sqlType.equalsIgnoreCase(&quot;float&quot;)) {
            return &quot;double&quot;;
        } else if (sqlType.equalsIgnoreCase(&quot;blob&quot;)) {
            return &quot;byte[]&quot;;
        } else if (sqlType.equalsIgnoreCase(&quot;blob&quot;)) {
            return &quot;byte[]&quot;;
        } else if (sqlType.equalsIgnoreCase(&quot;char&quot;)
                || sqlType.equalsIgnoreCase(&quot;varchar2&quot;)
                || sqlType.equalsIgnoreCase(&quot;varchar&quot;)) {
            return &quot;String&quot;;
        } else if (sqlType.equalsIgnoreCase(&quot;date&quot;)
                || sqlType.equalsIgnoreCase(&quot;timestamp&quot;)
                || sqlType.equalsIgnoreCase(&quot;timestamp with local time zone&quot;)
                || sqlType.equalsIgnoreCase(&quot;timestamp with time zone&quot;)) {
            return &quot;Date&quot;;
        } else if (sqlType.equalsIgnoreCase(&quot;int&quot;)) {
            return &quot;int&quot;;
        } else if (sqlType.equalsIgnoreCase(&quot;decimal&quot;)) {
            return &quot;BigDecimal&quot;;
        }
        return &quot;String&quot;;
    }

    /**
     * 获取列注释
     *
     * @param tableName
     * @param columnName
     * @return
     */
    private String getColComment(String tableName, String columnName) {
        String str = &quot;&quot;;
        String sql = &quot;select column_comment from INFORMATION_SCHEMA.Columns where&quot;
                + &quot; table_name='&quot; + tableName + &quot;' and table_schema='&quot; + databaseName + &quot;' and COLUMN_NAME = '&quot; + columnName + &quot;'&quot;;
        try {
            rs = pStemt.executeQuery(sql);
            while (rs.next()) {
                str = rs.getString(&quot;column_comment&quot;);
                if (null != str &amp;&amp; str.indexOf(&quot;\r\n&quot;) != -1) {
                    str = str.replace(&quot;\r\n&quot;, &quot;&quot;);
                }
                if (null != str &amp;&amp; str.indexOf(&quot;\n&quot;) != -1) {
                    str = str.replace(&quot;\n&quot;, &quot;&quot;);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return str;
    }

    /**
     * 规范类名
     *
     * @param tableName
     * @return
     */
    public String normTableName(String tableName) {
        String result = &quot;&quot;;

//        for (String temp : tablePre) {
//            int index = tableName.indexOf(temp.toLowerCase());//tb_在字符串中首次出现的位置
//            if (index &gt;= 0) {
//                tableName = tableName.substring(index + temp.length()); //截取tb_
        String[] names = tableName.split(&quot;_&quot;); //去除_
        if (null != names &amp;&amp; names.length &gt; 0) {
            for (String name : names) {
                result += upperFirstWord(name.toLowerCase());
            }
        }
//            }
//        }
        return result;
    }


    /**
     * 规范属性名
     *
     * @param propertyName
     * @return
     */
    public String normPropertyName(String propertyName) {
        String result = &quot;&quot;;
        String[] names = propertyName.split(&quot;_&quot;); //去除_
        if (null != names &amp;&amp; names.length &gt; 0) {
            for (int i = 0; i &lt; names.length; i++) {
                String name = names[i];
                if (i == 0) {
                    result += name.toLowerCase();
                } else {
                    result += upperFirstWord(name.toLowerCase());
                }
            }
        }
        return result;
    }


    /**
     * 首字母大写
     *
     * @param name
     * @return
     */
    public static String upperFirstWord(String name) {
        char[] cs = name.toCharArray();
        cs[0] -= 32;
        return String.valueOf(cs);
    }

    /**
     * 首字母小写
     *
     * @param name
     * @return
     */
    public static String lowerFirstWord(String name) {
        char[] cs = name.toCharArray();
        cs[0] += 32;
        return String.valueOf(cs);
    }

    /**
     * 出口 TODO
     *
     * @param args
     */

}

</code></pre>

    </div>
  </article>
<section id="comments">
</section>

</div><nav class="bar bar-footer clearfix" data-stick-bottom>
    <div class="bar-inner">
        <ul class="pager pull-left">
            <li class="prev">
                <a href="https://seventeenw.gitee.io/blogs/2020/06/springboot-quartz%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E8%A7%A3%E5%86%B3%E6%97%A0%E6%B3%95%E6%B3%A8%E5%85%A5%E5%8F%8A%E6%8C%81%E4%B9%85%E5%8C%96%E7%9A%84%E9%97%AE%E9%A2%98/" title="springboot&#43;quartz定时任务（解决无法注入bean及持久化的问题）"><i
                        class="icon icon-angle-left"
                        aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
            </li>
            <li class="next">
                <a href="https://seventeenw.gitee.io/blogs/2020/06/idea-springboot%E5%9B%BE%E6%A0%87%E4%B8%8D%E6%AD%A3%E7%A1%AE/"
                    title="IDEA Springboot图标不正确"><span>下一篇&nbsp;&nbsp;</span><i
                        class="icon icon-angle-right" aria-hidden="true"></i></a>
            </li>
            
            <li class="toggle-toc">
                <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false"
                    title="文章目录" role="button">
                    <span>[&nbsp;</span><span>文章目录</span>
                    <i class="text-collapsed icon icon-anchor"></i>
                    <i class="text-in icon icon-close"></i>
                    <span>]</span>
                </a>
            </li>
        </ul>
        <div class="bar-right">
            <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter"
                data-mobile-sites="weibo,qq,qzone"></div>
        </div>
    </div>
</nav>
</main><footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
<ul class="social-links">
    <li><a href="https://github.com/wengshiquan" target="_blank" title="github" data-toggle=tooltip data-placement=top >
            <i class="icon icon-github"></i></a></li>
    <li><a href="https://seventeenw.gitee.io/index.xml" target="_blank" title="rss" data-toggle=tooltip data-placement=top >
            <i class="icon icon-rss"></i></a></li>
    <li><a href="https://gitee.com/seventeenw" target="_blank" title="tags" data-toggle=tooltip data-placement=top >
            <i class="icon icon-tags"></i></a></li>
</ul>
  <div class="copyright">
    &copy;2017  -
    2020
    <div class="publishby">
        Theme by <a href="https://github.com/xiaoheiAh" target="_blank"> xiaoheiAh </a>base on<a href="https://github.com/xiaoheiAh/hugo-theme-pure" target="_blank"> pure</a>.
    </div>
  </div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
   window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/highlight.min.js"></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/rust.min.js"></script>
<script type="text/javascript"
   src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/dockerfile.min.js"></script>
<script>
hljs.configure({
  tabReplace: '    ', 
  classPrefix: ''     
                      
})
hljs.initHighlightingOnLoad();
</script>
<script type="text/javascript" src="https://seventeenw.gitee.io/blogs/js/application.js"></script>
<script type="text/javascript" src="https://seventeenw.gitee.io/blogs/js/plugin.js"></script>
<script>
      (function (window) {
          var INSIGHT_CONFIG = {
              TRANSLATION: {
                  POSTS: '文章',
                  PAGES: '页面',
                  CATEGORIES: '分类',
                  TAGS: '标签',
                  UNTITLED: '(未命名)',
              },
              ROOT_URL: 'https:\/\/seventeenw.gitee.io\/blogs',
              CONTENT_URL: 'https:\/\/seventeenw.gitee.io\/blogs\/searchindex.json ',
          };
          window.INSIGHT_CONFIG = INSIGHT_CONFIG;
      })(window);
      </script>
<script type="text/javascript" src="https://seventeenw.gitee.io/blogs/js/insight.js"></script>

  </body>
</html>
